﻿using Castle.DynamicProxy;
using Knife.Core.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;
using System.Web;

namespace Knife.Core.Aspect
{
    public class GlobalTransitionAspect : IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            object[] attributes = invocation.Method.GetCustomAttributes(typeof(GlobalTransitionAspect), false);
            if (attributes.Length > 0)
            {
                using (var scope = new TransactionScope())
                {
                    invocation.Proceed();
                    scope.Complete();
                }
            }
            else
            {
                invocation.Proceed();
            }

        }
    }
}